#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <pwd.h>
#include <unistd.h>
#include <time.h>
int main()
{
    struct stat st;
    int ret = stat("test.txt", &st);
    if(ret == -1)
    {
        perror("stat");
        return 0;
    }
    struct passwd* upwd = getpwuid(st.st_uid);
    struct passwd* gpwd = getpwuid(st.st_gid);
    struct tm atm;
    struct tm ctm;
    struct tm mtm;
    printf("包含些文件的设备ID：%ld\n", st.st_dev);
    printf("inode节点：%ld\n", st.st_ino);
    printf("文件权限：%d\n", st.st_mode);
    printf("硬链接数%ld\n", st.st_nlink);
    printf("所有者：%s\n", upwd->pw_name);
    printf("所有组：%s\n", gpwd->pw_name);
    printf("设备id(针对特殊设备%ld)\n",st.st_rdev);
    printf("大小 %ld\n",st.st_size);
    printf("系统块大小 %ld\n", st.st_blksize);
    printf("占用块数量 %ld\n", st.st_blocks);
    localtime_r((time_t*)&st.st_atim, &atm);
    printf("最后访问时间%04d-%02d-%02d\n", atm.tm_year + 1900, atm.tm_mon+1, atm.tm_mday);
    printf("最后修改时间 %ld\n", st.st_mtime);
    printf("最后状态改变时间%ld\n", st.st_ctime);
    return 0;
}
